package suanfa;

import java.util.Arrays;

public class MidelNumbers1
{
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {

        int n = nums1.length;
        int m = nums2.length;
        int all = m + n;
        double midel = 0;
        int[] newArray = new int[all];

        for (int i = 0; i < all; i++)
        {
            if (i < n)
            {
                newArray[i] = nums1[i];
            }
            else
            {
                newArray[i] = nums2[i-n];
            }
        }
        Arrays.sort(newArray);

        if (all % 2 != 0)
        {
            midel = newArray[all/2];
            return midel;
        }
        midel = newArray[all / 2] + newArray[all / 2 - 1];

        return midel/2.0;
    }

    public static void main(String[] args)
    {
        MidelNumbers1 midelNumbers = new MidelNumbers1();

        int[] a = {1,2};
        System.out.println("=================");
        int[] b = {3,4};
        double medianSortedArrays = midelNumbers.findMedianSortedArrays(a, b);
        System.out.println(medianSortedArrays);
    }
}
